package de.szut.ita13sommerfeld.apacheanalyser.libaries;

import java.util.Set;


public class ResourceLibary extends Libary<String, Integer> {

	private static final long serialVersionUID = 1L;
	
	public ResourceLibary() {

	}
	
	/**
	 * 
	 * @return returns the most downloaded resource
	 */
	public Entry<String, Integer> getMostDownloadedResource() {
		Entry<String, Integer> mostDownloaded = null;
		Set<Entry<String, Integer>> entrySet = entrySet();
		for(Entry<String, Integer> currentResource : entrySet) {
			if(mostDownloaded == null) mostDownloaded = currentResource;
			if(mostDownloaded.getValue() < currentResource.getValue()) {
				mostDownloaded = currentResource;
			}
		}
		return mostDownloaded;
	}
	/**
	 * prints out all values of the resource libary
	 */

	public void showValues() {
		Set<Entry<String, Integer>> entrySet = entrySet();
		for(Entry<String, Integer> entry : entrySet) {
			System.out.println(entry.getKey().toString() + " " + entry.getValue());
		}
	}
	
	/**
	 * 
	 * @param currentResource resource as string to check if its already in the libary
	 * @param resourceLibary libary that the get the currentResource
	 */
	public static void addResourceToLibary(String currentResource, ResourceLibary resourceLibary) {
		if(!resourceLibary.containsKey(currentResource)) {
			resourceLibary.put(currentResource, new Integer(1));
		} else {
			resourceLibary.put(currentResource, resourceLibary.get(currentResource) + 1);
		}
	}

}
